﻿using System;
using System.Collections.Generic;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Context;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Service;
using System.Linq;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Script;
using System.Text.RegularExpressions;
using ZyGames.Framework.Net;
using ZyGames.DZPocker.Tools;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 房主点击玩家头像允许玩家申请筹码不需要房主确认
	/// </summary>
	public class Action30088 : BaseAction
	{
		int tableId;
		int userId;
		int posId;

		private bool result = false;
		public Action30088(HttpGet actionGetter)
			: base((short)ActionType.DZApplyChipWithoutCommit, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("TableId", ref tableId) &&
				httpGet.GetInt("UserId", ref userId))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			var _currentTable = GameRoom.Current.GetTableData(tableId);
			if (_currentTable == null)
			{
				Tool.WriteWarmingLine("消息30088获得房间不存在");
				return false;
			}
			var _currentGameUser = GameTable.Current.GetUser(userId);
			if(_currentGameUser == null)
			{
				Tool.WriteWarmingLine("消息30088 玩家不存在");
				return false;
			}
			result = _currentTable.AddForceApplyChipWithoutConfirm(userId);
			return true;
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(this.tableId);
			this.PushIntoStack(this.result);
		}
	}
}
